package com.ftg.shopping.sp_orderinfo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.orderdetails.entity.Orderdetails;
import com.ftg.shopping.orderdetails.mapper.OrderdetailsMapper;
import com.ftg.shopping.sp_orderinfo.entity.SpOrderinfo;
import com.ftg.shopping.sp_orderinfo.mapper.SpOrderinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SpOrderinfoService {

    @Autowired
    SpOrderinfoMapper spOrderinfoMapper;

    @Autowired
    OrderdetailsMapper orderdetailsMapper;

    public LayuiPage<SpOrderinfo> layuipage(int page, int limit, String dname) {
        IPage<SpOrderinfo> ip = new Page<>(page, limit);
        QueryWrapper qw = new QueryWrapper();
        qw.like("orderid", dname);
        spOrderinfoMapper.selectPage(ip, dname == null || dname.equals("") ? null :  qw);
        return new LayuiPage<>(ip);

    }

    public int update(SpOrderinfo d) {
        return spOrderinfoMapper.updateById(d);
    }



//主键联动删除
    @Transactional(rollbackFor = Exception.class)
    public int del1(int orderid) {
        spOrderinfoMapper.deleteById(orderid);
        orderdetailsMapper.deleteById(orderid);
        return  1;
    }
//联动添加
    @Transactional(rollbackFor = Exception.class)
    public int insert(SpOrderinfo g, Orderdetails b) {
        spOrderinfoMapper.insert(g);
        orderdetailsMapper.insert(b);
        return 1;
    }
}
